package com.cskaoyan.day24.Constructor;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class API {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        Class<?> aClass = Class.forName("com.cskaoyan.day24.Constructor.Person");
        Constructor<?>[] constructors = aClass.getConstructors();
        for (Constructor<?> constructor : constructors) {
            System.out.println(constructor);
        }


        System.out.println("----------------------------------------------------------");
        Constructor<?>[] declaredConstructors = aClass.getDeclaredConstructors();
        for (Constructor<?> declaredConstructor : declaredConstructors) {
            System.out.println(declaredConstructor);
        }

        System.out.println("----------------------------------------------------------");
        Constructor<?> constructor = aClass.getConstructor(int.class, String.class);
        System.out.println(constructor);

        System.out.println("----------------------------------------------------------");
        Constructor<?> constructor1 = aClass.getDeclaredConstructor(String.class);
        System.out.println(constructor1);

        Object name = constructor.newInstance(1, "name");
        System.out.println(name);

        constructor1.setAccessible(true);
        Object xxx = constructor1.newInstance("xxx");
        System.out.println(xxx);


    }
}


